interface FilterState {
    jobIds: number[]
}
export function useJobSelect(changeHandler: IFn) {
    const filterState = ref<FilterState>(getInitialFilterState())
    const allJobOption = <IOption<number>>{
        label: "全部职位",
        value: AllValue
    }
    const jobOptions = computed(() => {
        return [allJobOption]
    })
    const {
        selects: jobSelects,
        handleItemTap: handleJobTap,
        apply: applyJob,
    } = useOptionSelect<number>({
        mode: "single",
        allValue: AllValue,
        availableOptions: jobOptions,
        rollbackSync: false,
        syncSelects(selects, isAll) {
            if (isAll) {
                filterState.value!.jobIds.length = 0
            } else {
                filterState.value!.jobIds = [...selects]
            }
            applyJob()
            changeHandler()
        },
    })
    const selectedJob = computed(() => {
        const [job] = jobSelects.value
        return jobOptions.value.find(l => l.value === job)
    })
    function getInitialFilterState(): FilterState {
        return {
            jobIds: [],
        }
    }
    function getJobParams() {
        return filterState.value
    }
    return {
        getJobParams,
        jobOptions,
        jobSelects,
        selectedJob,
        handleJobTap
    }
}